package com.zgkxzx.java.mutilThread.myLock;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;

/**
 * 创建者 zgkxzx
 * 日期   1/4/18
 * 描述
 */

public class MyAbstractQueuedSynchronizer extends AbstractQueuedSynchronizer {

    private AtomicInteger state;


    public MyAbstractQueuedSynchronizer() {
        state = new AtomicInteger(0);
    }


    @Override
    protected boolean tryAcquire(int arg) {
        return state.compareAndSet(0, 1);
    }

    @Override
    protected boolean tryRelease(int arg) {
        return state.compareAndSet(1, 0);
    }

}
